package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.request.ProjectRequest;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.project.data.entity.ProjectCatalog;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 项目请求对象转换成实体对象
 */

public class ProjectEntityConvert implements Converter<Project, ProjectRequest> {

    @Override
    public Project convert(ProjectRequest source) {
        Project result = new Project();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCreator() != null) {
            User creator = new User();
            creator.setId(source.getCreator());
            result.setCreator(creator);
        }
        if (source.getCatalog() != null) {
            ProjectCatalog catalog = new ProjectCatalog();
            catalog.setId(source.getCatalog());
            result.setCatalog(catalog);
        }
        if (source.getCharger() != null) {
            User charger = new User();
            charger.setId(source.getCharger());
            result.setCharger(charger);
        }
        return result;
    }
}

